#pragma once
#include <iostream>
#include <semaphore.h>

//封装信号量，里面就得有信号量
class Sem
{
public:
    Sem(int num):_initnum(num)
    {
        sem_init(&_sem,0,_initnum);
    }
    //申请信号量
    void P()
    {
        int n = sem_wait(&_sem);
        (void)n;
    }
    //释放信号量
    void V()
    {
        int n = sem_post(&_sem);
        (void)n;
    }
    ~Sem()
    {
        sem_destroy(&_sem);
    }
private:
    sem_t _sem;
    int _initnum;//初始信号量个数
};